﻿using AutoMapper;
using CNav.Business.Services;
using CNav.Controllers;
using CNav.Domain.Admin;
using CNav.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace CNav.Controllers
{
    [Authorize]
    public class RenderController : BaseController
    {
        public ActionResult Index(int formId)
        {
            var model = GetRenderControlListModel(formId);

            return View(model);
        }

        public ActionResult RenderView(int formId)
        {
            var model = GetRenderControlListModel(formId);

            return PartialView(model);
        }

        private RenderControlListModel GetRenderControlListModel(int formId)
        {
            var response = Service.Get<IUiService>().GetCustomFormControls(formId);

            var model = new RenderControlListModel();
            model.FormID = formId;
            model.Controls = response.Data.Select(Mapper.Map<RenderControlModel>).OrderBy(d => d.DisplayOrder).ToList();
            return model;
        }
    }
}
